<?php
$title='相册管理';
define('IN_TG', 'admin_article');
include('admin_header.php');
//判断是否存在p参数，存在则使用传递来的页码，不存在则使用默认值1
$page=isset($_GET['p'])?$_GET['p']:1;
$sql = "select d.tg_id,d.tg_name,d.tg_type,d.tg_face,d.tg_dir,d.tg_date,(select count(*) from tg_photo as p where p.tg_sid=d.tg_id) as photo_num from tg_dir as d order by tg_date limit ".intval(($page-1)*5).",5";
$res = _query($sql);
$sql="select tg_id from tg_dir";
$total=_num_rows(_query($sql));
$page_total=ceil($total/5);
?>
<div class="row">
    <div class="col-lg-12">
        <h1>多用户留言 <small>后台管理系统</small></h1>
        <ol class="breadcrumb">
            <li><a href="admin_index.php"><i class="fa fa-home"></i> 首页</a></li>
            <li class="active"><i class="fa fa-table"></i> <?php echo $title;?></li>
        </ol>
    </div>
</div><!-- /.row -->

<div class="row">
    <div class="col-lg-12">
        <div class="table-responsive">
            <table class="table table-bordered table-hover tablesorter">
                <thead>
                <tr>
                    <th>ID <i class="fa fa-sort"></i></th>
                    <th>相册名 <i class="fa fa-sort"></i></th>
                    <th>相册是否加密 <i class="fa fa-sort"></i></th>
                    <th>相册封面 </th>
                    <th>相册路径 <i class="fa fa-sort"></i></th>
                    <th>新建相册时间 <i class="fa fa-sort"></i></th>
                    <th>相片数量 <i class="fa fa-sort"></i></th>
                    <th>相片管理</th>
                </tr>
                </thead>
                <tbody>
                <?php while($row = _fetch_array_list($res)): ?>
                    <tr>
                        <td><?php echo $row['tg_id'];?></td>
                        <td><?php echo $row['tg_name'];?></td>
                        <td><?php echo $row['tg_type']==1?'加密':'不加密';?></td>
                        <td><img src="<?php echo $row['tg_face']==''?'images/photo.jpg':$row['tg_face'];?>" title="<?php echo $row['tg_name'];?>" alt="<?php echo $row['tg_name'];?>"></td>
                        <td><?php echo $row['tg_dir'];?></td>
                        <td><?php echo $row['tg_date'];?></td>
                        <td><?php echo $row['photo_num'];?></td>
                        <td><a href="admin_photo.php?id=<?php echo $row['tg_id'];?>" class="btn btn-link btn-lg fa fa-picture-o"> 查看</a></td>
                    </tr>
                <?php endwhile;?>
                </tbody>
            </table>
            <div class="text-right">
                <ul class="pagination pagination-lg">
                    <li <?php if($page==1):?>class="disabled" <?php endif;?>><a href="?p=1">«</a></li>
                    <?php for($i=1;$i<=$page_total;$i++)
                    {
                        if ($page == $i) {
                            echo '  <li class="active"><a href="?p='.$i.'">'.$i.'</a></li>';
                        } else {
                            echo '  <li><a href="?p='.$i.'">'.$i.'</a></li>';
                        }
                    }
                    ?>
                    <li <?php if($page==$page_total):?>class="disabled" <?php endif;?>><a href="?p=<?php echo $page_total;?>">»</a></li>
                </ul>
            </div>
        </div>
    </div>
</div><!-- /.row -->



</div><!-- /#page-wrapper -->
<?php include('admin_footer.php');?>
<script>
    $("#admin_photo").attr('class','active');
</script>